/*

  Color images creator

  Copyright © 2010 - 2011 F.Hroch (hroch@physics.muni.cz)

  This file is part of Munipack.

  Munipack is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  Munipack is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with Munipack.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "munipack.h"


bool Munipack::coloring(MuniCmdLineParser& cmd)
{
  MuniProcess *action = new MuniProcess(&pipe,"coloring");
  pipe.push(action);

  wxString a;

  if( cmd.Found("c",&a) )
    action << ("COLORSPACE = '" + a + "'");

  if( cmd.Found("ct",&a) )
    action << ("CTABLE = '" + a + "'");
#ifdef MUNIPACK_DATA_PATH
  else
    action << ("CTABLE = '"+wxString(MUNIPACK_DATA_PATH)+"/ctable.dat'");
#endif

  if( cmd.Found("o",&a) )
    action << ("OUTPUT = '" + a + "'");

  if( cmd.Found("b",&a) )
    action << ("BITPIX = " + a);

  a.Printf("NBAND = %d",(int) cmd.GetParamCount() - 1);
  action << a;

  for(size_t i = 1; i < cmd.GetParamCount(); i++) {
    wxString par(cmd.GetParam(i));
    int p = par.Find(",");
    if( p == wxNOT_FOUND )
      action << ("'" + par + "' ''");
    else
      action << ("'" + par.Mid(0,p) + "' '" + par.Mid(p+1) + "'");
  }

  pipe.Start();

  return true;
}
